var express = require('express');
var router = express.Router();
var sql = require('./../sql');
var Echarts = require('./../sql/echarts');
var uuid = require('node-uuid')



router.get('/find', (req, res) => {
    let { userid } = req.query
    console.log(userid)
    sql.find(Echarts, { userid }).then((data) => {
        if (data.length === 0) {
            res.send({
                code: 200,
                message: '没有反馈记录',
                data
            })
        } else {
            res.send({
                code: 200,
                message: '获取到反馈信息',
                data
            })
        }
    })
})



router.post('/add', (req, res) => {
    let { userid, username, body, kindid ,value} = req.body
    let PLid = 'pinglun_' + uuid.v1()
    sql.insert(Echarts, { userid, username, body, kindid, PLid ,value}).then(() => {
        res.send({
            code: 200,
            message:'添加评论成功'
        })
    })
})


module.exports = router